<extend name="./ljfbase" />
<block name="main">
    <script src="__PUBLIC__/js/jquery.min.js"></script>
    <div class="container">
        <div class="row">

            <div class="col-md-2">
                <hr>

                <ul>
                    <li>好友动态</li>
                    <li>特别关心</li>
                    <li>@与我相关</li>
                    <li>那年今日</li>
                    <li>我的收藏</li>
                </ul>

                <ul>
                    <li>礼物</li>
                    <li>花藤</li>
                </ul>
            </div>

            <div class="col-md-7">
                <hr>
                <div class="create">
                    <textarea class="form-control" rows="3" name="content" placeholder="说说你的心情"></textarea><br>
                    <input type="file" name="pic[]" multiple="multiple" value="选择图片" id="pic"/>
                    <div>
                        <ul id="pic_tmp">
                        
                        </ul>    
                    </div>
                    <button class="action-subsay">发表说说</button>
                </div>

                <div class="saylist" id="saylist">
                    <!-- 动态列表START! -->
                    <volist name="list" id="data">
                        <div class="panel panel-default sayitem">
                            <div class="panel-heading">
                                <div class="media">
                                    <a class="pull-left" href="{:U('Home/Index/index',array('user_id'=>$data['user']['id']))}">
                                        <img class="media-object img-rounded" src="__PUBLIC__{$data.user.zonedp}" height="50" width="50" alt="头像">
                                    </a>
                                    <div class="media-body">
                                        <a href="{:U('Home/Index/index',array('user_id'=>$data['user']['id']))}">
                                            <div class="media-heading">
                                                <strong>{$data.user.nickname}</strong>
                                            </div>
                                        </a>
                                        <div class="small">
                                            {$data.ctime|date="Y-m-d H:i:s",###}
                                        </div>                          
                                    </div>
                                </div>
                            </div>

                            <div class="panel-body">
                                <p>
                                    <a href="{:U('Home/Log/detail',array('logid'=>$data['id'],'user_id'=>$data['uid']))}">{$data.title}</a><br>{$data.content}<br>
                                </p>
                                    
                                <volist name="data['photo']" id="val">
                                    <div class="pull-left mt6 mr3 ml3">
                                        <img src="__PUBLIC__/uploads/{$val.path}" height="175" width="200">
                                    </div>
                                </volist>
                                
                                <div class="clear"></div>
                                <div class="actions">
                                    <div class="btn-group">
                                        <a type="{$data.type}" class="act-fav btn btn-link" dataid="{$data.id}">赞({$data.goodnum})</a>
                                        <a type="button" class="btn btn-link">评论({$data.comnum})</a>
                                        <a type="{$data.type}" class="act-del btn btn-link" dataid="{$data.id}">删除</a>
                                        <a type="{$data.type}" class="btn btn-link" dataid="{$data.id}">举报</a>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="panel-footer combody">
                                <!-- 评论列表START! -->
                                <volist name="data['comment']" id="vo">
                                    <div class="media comitem">
                                        <a class="pull-left" href="{:U('Home/Index/index',array('user_id'=>$vo['user']['id']))}">
                                            <img class="media-object img-rounded" src="__PUBLIC__{$vo.user.zonedp}" height="35" width="35" alt="头像">
                                        </a>
                                        <div class="media-body hfbody">
                                            <p class="small" >
                                                <a href="{:U('/Home/Index/index',array('user_id'=>$vo['user']['id']))}">{$vo.user.nickname}:</a>
                                                {$vo.content}
                                            </p> 
                                            <div class="small">
                                                {$vo.ctime|date="Y-m-d H:i:s",###}
                                                <a href="javascript:void(0)" class="act-com-hf" comid="{$vo.id}" hfid="{$vo.uid}" type="{$data.type}">回复</a>
                                                <a href="javascript:void(0)" class="act-com-del" dataid="{$vo.id}" type="{$data.type}">删除</a>
                                            </div>
                                            <!-- 回复列表START! -->
                                            <volist name="vo['hflist']" id="val">
                                                <div class="media replyitem">
                                                    <a class="pull-left" href="{:U('Home/Index/index',array('user_id'=>$val['user1']['id']))}">
                                                        <img class="media-object img-rounded" src="__PUBLIC__{$val.user1.zonedp}" height="35" width="35" alt="头像">
                                                    </a>
                                                    <div class="media-body">
                                                        <p class="small" >
                                                            <a href="{:U('/Home/Index/index',array('user_id'=>$val['user1']['id']))}">{$val.user1.nickname}</a>&nbsp;回复&nbsp<a href="{:U('/Home/Index/index',array('user_id'=>$val['user2']['id']))}">{$val.user1.nickname}</a>：{$val.content}
                                                        </p> 
                                                        <div class="small">
                                                            {$val.ctime|date="Y-m-d H:i:s",###}
                                                            <a href="javascript:void(0)" class="act-com-hf" comid="{$vo.id}" hfid="{$val.uid}" type="{$data.type}">回复</a>
                                                            <a href="javascript:void(0)" class="act-hf-del" dataid="{$val.id}" type="{$data.type}">删除</a>
                                                        </div>                
                                                    </div>
                                                </div>
                                            </volist><!-- 回复列表END! -->
                                            <div class="huifu"  style="display:none">
                                                <textarea class="form-control" rows="2" name="content"  placeholder=""></textarea>
                                                <button class="action-hf btn btn-primary btn-sm pull-right mt10">发表</button>
                                            </div>                          
                                        </div>
                                    </div>
                                </volist><!-- 评论列表END! -->
                                <div class="mt10 combtn">
                                    <textarea name="comment" class="form-control" rows="1" placeholder="我也说一句"></textarea>
                                    <button class="action-comment btn btn-primary btn-sm pull-right mt10 md10" value="{$data.id}" type="{$data.type}">发表</button>
                                    <div class="clear"></div>
                                </div>
                            </div>
                        </div>
                    </volist><!-- 说说列表END! -->
                </div>
            </div>
            <div class="col-md-3">
                <hr>
                <div>
                    <span class="ml40"><strong>{$week}</strong></span>
                    <button class="ml10 btn btn-primary act-sign">签到</button>
                    <span class="ml10">{$signday}</span>天
                </div>
                <div>
                    <ul>
                        <li>谁看过我</li>
                            <volist name="whocome" id="vo">
                                <a href="{:U('/Home/Index/index',array('user_id'=>$vo[uid]))}">
                                    <img src="__PUBLIC__{$vo.user.zonedp}" width="35" height="35">
                                    {$vo.user.nickname}
                                </a>
                                {$vo.vtime|date="Y-m-d H:i:s",###}<br>
                            </volist>  
                        <li>我看过谁</li>
                            <volist name="seewho" id="vo">
                                
                                <a href="{:U('/Home/Index/index',array('user_id'=>$vo[vid]))}">
                                    <img src="__PUBLIC__{$vo.user.zonedp}" width="35" height="35">
                                    {$vo.user.nickname}
                                </a>
                                {$vo.vtime|date="Y-m-d H:i:s",###}<br>
                            </volist>
                    </ul>
                </div>
            </div>

        </div>
    </div>
    <script>
        //处理签到
        $('.container').on('click','.act-sign',function(){
            var self=$(this);
            $.ajax({
                type: "POST",
                url: "{:U('Home/Center/sign')}",
                dataType: "json",
                success: function(rs){
                    if(rs.status == 'success'){
                        alert(rs.msg);
                        self.html('已签到');
                        self.next().html(rs.num);
                    }else{
                        alert(rs.msg);
                    }
                }
            });
        });
        //删除动态
        $('#saylist').on('click','.act-del',function(){
            var self = $(this);
            var id=self.attr('dataid');
            var type=self.attr('type');
            if(type=='Say'){
                url = "{:U('/Home/Say/del')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/del')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/del')}";
            }
            $.ajax({
                type: "POST",
                url: url,
                data: {'id':id},
                dataType: "json",
                success: function(rs){
                    if(rs.status == 'success'){
                        self.parents('div.sayitem').remove();
                    }else{
                        alert(rs.msg);
                    }
                }
            });
        });

        //删除评论
        $('#saylist').on('click','.act-com-del',function(){
            var self = $(this);
            var id=self.attr('dataid');
            var type=self.attr('type');
            if(type=='Say'){
                url = "{:U('/Home/Say/delcom')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/delcom')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/delcom')}";
            }
            $.ajax({
                type: "POST",
                url: url,
                data: {'id':id},
                dataType: "json",
                success: function(rs){
                    if(rs.status == 'success'){
                        self.parents('div.comitem').remove();
                    }else{
                        alert(rs.msg);
                    }
                    
                }
            });
        });

        //回复删除
        $('#saylist').on('click','.act-hf-del',function(){
            var self = $(this);
            var id = self.attr('dataid');
            var type = self.attr('type');
            if(type=='Say'){
                url = "{:U('/Home/Say/delhf')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/delhf')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/delhf')}";
            }
            $.ajax({
                type:'POST',
                url:url,
                data:{'id':id},
                dataType:"json",
                success:function(rs){
                    if(rs.status == 'success'){
                        self.parents('div.replyitem').remove();
                    }else{
                        alert(rs.msg);
                    }
                }
            });
        });

        //点赞功能实现
        $("#saylist").on('click','.act-fav',function(){
            var self=$(this);
            var id=self.attr('dataid');
            var type=self.attr('type');
            if(type=='Say'){
                url = "{:U('/Home/Say/fav')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/fav')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/fav')}";
            }
            $.ajax({
                type:'POST',
                url:url,
                data:{'id':id},
                dataType:"json",
                success:function(rs){
                    if(rs.status=='success'){
                        self.html(rs.btn);
                    } else {
                        alert(rs.msg);
                    }
                }
            });
        });

        //评论回复功能实现
        $("#saylist").on('click','.act-com-hf',function(){
            // debugger;
            var self1 = $(this);
            var comid = self1.attr('comid');
            var hfid = self1.attr('hfid');
            var type = self1.attr('type');
            var div = self1.parents('div.hfbody').children(".huifu");
            div.show();
            self1.parents('div.combody').children('.combtn').hide();
            div.children('.action-hf').attr({ comid: comid, hfid: hfid, type: type});
        });
        $("#saylist").on('click','.action-hf',function(){
            var self2 = $(this);
            var comid = self2.attr('comid');
            var hfid = self2.attr('hfid');
            var type = self2.attr('type');
            var content = self2.prev().val().trim();
            if(content.length==0){
                return false;
            }
            if(type=='Say'){
                url = "{:U('/Home/Say/comhf')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/comhf')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/comhf')}";
            }
            $.ajax({
                type:'POST',
                url:url,
                data:{'com_id':comid,'hfid':hfid,'content':content},
                dataType:"json",
                success:function(rs){
                    if(rs.status == 'success'){
                        var divs = '<div class="media replyitem">'+
                                    '<a class="pull-left" href="page-activity.html#">'+
                                        '<img class="media-object img-rounded" src="__PUBLIC__'+rs.zonedp1+'" height="35" width="35" alt="头像">'+
                                    '</a>'+
                                    '<div class="media-body">'+
                                        '<p class="small" >'+
                                            '<a href="javascript:void(0)">'+rs.name1+'&nbsp</a><a href="javascript:void(0)">@'+rs.name2+'</a>:'+rs.content+
                                        '</p> '+
                                        '<div class="small">'+
                                            rs.ctime+
                                            '<a href="javascript:void(0)" class="act-com-hf" comid="'+comid+'" hfid="'+hfid+'" type="'+type+'">回复</a>'+
                                            '<a href="javascript:void(0)" class="act-hf-del" dataid='+rs.id+' type="'+type+'">删除</a>'+
                                        '</div> '+                         
                                    '</div>'+
                                '</div>';
                        self2.parent().before(divs);
                        self2.prev().val(''); // 清空输入框
                        self2.parent().hide();
                        self2.parents('div.combody').children('.combtn').show();
                    }
                }
            });
        });

        //提交评论
        $('#saylist').on('click','.action-comment',function(){
            var self = $(this);
            var content = $(this).prev().val().trim();
            var who_id = $(this).attr('value');
            var type = $(this).attr('type');
            if(content.length==0){
                return false;
            }
            if(type=='Say'){
                url = "{:U('/Home/Say/tosavecomment')}";
            }
            if(type=='Log'){
                url = "{:U('/Home/Log/comment')}";
            }
            if(type=='Album'){
                url = "{:U('/Home/Album/comment')}";
            }

            $.ajax({
                type: "POST",
                url: url,
                data:  {"content":content,'who_id':who_id},
                dataType: "json",
                success: function(rs){
                    if(rs.status == 'success'){
                        var commentlist = self.parent();
                        var divs = '<div class="media comitem">'+
                                        '<a class="pull-left" href="page-activity.html#">'+
                                            '<img class="media-object img-rounded" src="__PUBLIC__'+rs.zonedp+'" height="35" width="35" alt="头像">'+
                                        '</a>'+
                                        '<div class="media-body hfbody">'+
                                            '<p class="small" >'+
                                                '<a href="javascript:void(0)">'+rs.name+':</a>'+
                                                rs.content+
                                            '</p>'+
                                            '<div class="small">'+
                                                rs.ctime+
                                                '<a href="javascript:void(0)" class="act-com-hf" type="'+type+'" comid="'+rs.id+'" hfid="'+rs.uid+'">回复</a>'+
                                                '<a href="javascript:void(0)" class="act-com-del" type="'+type+'" dataid='+rs.id+'>删除</a>'+
                                            '</div>'+ 
                                            '<div class="huifu"  style="display:none">'+
                                                '<textarea class="form-control" rows="2" name="content"  placeholder=""></textarea>'+
                                                '<button class="action-hf btn btn-primary btn-sm pull-right mt10">发表</button>'+
                                            '</div>'+               
                                        '</div>'+
                                    '</div>';
                        commentlist.before(divs);
                        self.prev().val(''); // 清空输入框
                    }
                }
            });
        });
        
        //提交说说
        $('.action-subsay').on('click',function(){
            var content = $("textarea[name='content']").val().trim();
            var img = [];
            $.each($('.imgpath'),function(i,n){
                img[i] = $(".imgpath").eq(i).val();
            })
            if(content.length==0){
                return false;
            }
            // alert(content);

            $.ajax({
                type: "POST",
                url: "{:U('Home/Say/tosave')}",
                data: {"content":content,'img':img},
                dataType: "json",
                success: function(rs){
                    if(rs.status == 'success'){
                        var saylist = $("#saylist");
                        var pic = "";
                        // console.log(img);
                        $.each(img,function(i,n){
                            pic += '<img width="200" height="175" src="__PUBLIC__/uploads/'+ n +'">';
                        });
                        var divs = '<div class="panel panel-default sayitem">'+
                                    '<div class="panel-heading">'+
                                        '<div class="media">'+
                                            '<a class="pull-left" href="page-activity.html">'+
                                                '<img class="media-object img-rounded" src="__PUBLIC__'+ rs.zonedp +'" alt="头像" height="50" width="50"></a>'+
                                            '<div class="media-body">' +
                                                '<a href="page-activity.html#">' +
                                                    '<div class="media-heading">' + rs.name +
                                                        '</div> </a>' +
                                                '<div class="small">' + 
                                                    rs.ctime +
                                                '</div>' +
                                            '</div>' +
                                        '</div>' +
                                    '</div>' +
                                    '<div class="panel-body">'+
                                        '<p>'+
                                        rs.content +'<br>'+
                                        pic +
                                        '</p>'+
                                        '<div class="actions">'+
                                            '<div class="btn-group">'+
                                                '<a type="Say" class="act-fav btn btn-link" dataid="'+rs.id+'">赞</a>'+
                                                '<a type="button" class="btn btn-link">评论</a>'+
                                                '<a type="Say" class="act-del btn btn-link" dataid="'+rs.id+'">删除</a>'+
                                                '<a type="Say" class="btn btn-link" dataid="'+rs.id+'">举报</a>'+                   
                                            '</div>'+
                                        '</div>'+
                                    '</div>'+
                                    '<div class="panel-footer combody">'+
                                        '<div class="mt10 combtn">'+
                                    '<textarea name="comment" class="form-control" rows="1" placeholder="我也说一句"></textarea>'+
                                    '<button class="action-comment btn btn-primary btn-sm pull-right mt10 md10" value="'+rs.id+'" type="Say">发表</button>'+
                                    '<div class="clear"></div>'+
                                '</div>'+
                                    '</div>'+
                                '</div>';
                        saylist.prepend(divs);
                        $('#pic_tmp').empty(); // 删除ajax加载过来的图片
                        $("textarea[name='content']").val(''); // 清空输入框
                        $('#pic').val(''); // 清空选择的照片
                    }
                }
            });
        });

        //ajax上传图片
        $("#pic").on('change',function(){
            var formData = new FormData();
            $.each($('#pic')[0].files, function(i, file) {
                formData.append('upload_file[]', file);
            });
        
            $.ajax({
                url: '{:U("Home/Say/uploadimg")}',
                type: 'POST',
                cache: false,
                data: formData,
                dataType: "json",
                processData: false,
                contentType: false,
                success: function(rs){
                    // debugger;
                    var imgbox = $('#pic_tmp');
                    var lis = "";
                    $.each(rs.info,function(i,n){
                        lis += '<li><img width="100" height="100" src="__PUBLIC__/uploads/' + n.savepath + n.savename +'"><input class="imgpath" type="hidden" name="img[]" value="'+ n.savepath + n.savename +'"></li>' ;
                    });
                    imgbox.append(lis);
                }
            });

        });

        //ajax删除图片
        $('#pic_tmp').on('click','img',function(){
            var self=$(this);
            var picname = self.next().val();
            self.parents('li').remove();
            $('#pic').val(''); // 清空选择的照片

            //ajax删除服务器的图片
            $.ajax({
                type: "POST",
                url: "{:U('delpic')}",
                data: {'picname':picname},
                dataType: "json",
                success: function(rs){
                    // alert(rs.msg);
                }
            });
        });
    </script>
</block>